from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction, QStackedWidget
from PyQt5.QtGui import QColor, QIcon
import qtawesome as qta

from pages.Ass import Ass
from pages.DataManage import DataManage
from pages.PlatformIssues import PlatformIssues
from pages.Tools import Tools


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initToolBar()
        self.initPages()
        # 设置主窗口的大小和标题
        self.setGeometry(200, 200, 1400, 800)
        self.setWindowTitle("QToolBar Example")

    def initToolBar(self):
        # 创建一个工具栏
        self.toolbar = QToolBar("My Toolbar")

        # 创建一些动作
        icon_new = qta.icon('ei.file-new-alt', color=QColor('#1296db'))
        new_action = QAction(icon_new, "中台排查", self)
        new_action.triggered.connect(self.open_issues)

        icon_open = qta.icon('ei.folder-open', color=QColor('#1296db'))
        open_action = QAction(icon_open, "常用工具", self)
        open_action.triggered.connect(self.open_tools)

        icon_save = qta.icon('fa5s.save', color=QColor('#1296db'))
        save_action = QAction(icon_save, "ASS接口", self)
        save_action.triggered.connect(self.open_ass)

        fa5_icon = qta.icon('mdi6.content-cut', color=QColor('#1296db'))
        cut_action = QAction(fa5_icon, "数据管理", self)
        cut_action.triggered.connect(self.open_data)

        # 将动作添加到工具栏
        self.toolbar.addAction(new_action)
        self.toolbar.addAction(open_action)
        self.toolbar.addAction(save_action)
        self.toolbar.addAction(cut_action)

        # 将工具栏添加到主窗口
        self.addToolBar(self.toolbar)
        self.toolbar.setIconSize(QSize(23, 23))
        self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

    def initPages(self):
        self.stackWeiget = QStackedWidget()
        platformIssues = PlatformIssues()
        tools = Tools()
        ass = Ass()
        dataManage = DataManage()
        self.stackWeiget.addWidget(platformIssues)
        self.stackWeiget.addWidget(tools)
        self.stackWeiget.addWidget(ass)
        self.stackWeiget.addWidget(dataManage)
        self.setCentralWidget(self.stackWeiget)

    def open_issues(self):
        self.stackWeiget.setCurrentIndex(0)

    def open_tools(self):
        self.stackWeiget.setCurrentIndex(1)

    def open_ass(self):
        self.stackWeiget.setCurrentIndex(2)

    def open_data(self):
        self.stackWeiget.setCurrentIndex(3)
